<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>修改评论</title>
    <link rel="icon" href="./favicon/favicon.ico" type="image/x-icon">
    <link href="https://cdn.bootcdn.net/ajax/libs/bootstrap/5.3.2/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/bootstrap-icons/1.11.1/font/bootstrap-icons.min.css">
    <script src="js/bootstrap.bundle.min.js"></script>
</head>
<body class="p-4">
<!-- 修改评论模态框 -->
<div class="modal fade" id="editCommentModal" tabindex="-1" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">修改评论</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>
            <form id="editCommentForm" action="${pageContext.request.contextPath}/commentServlet" method="post">
                <div class="modal-body">
                    <input type="hidden" name="method" value="updateComment">
                    <input type="hidden" id="editCommentId"   name="id">
                    <input type="hidden" id="editArticleId"  name="articleId">
                    <input type="hidden" id="editUserId"     name="userId">
                    <div class="mb-3">
                        <label class="form-label">内容</label>
                        <textarea class="form-control" id="editContent" name="content" rows="3" required></textarea>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
                    <button type="submit" class="btn btn-primary">保存</button>
                </div>
            </form>
        </div>
    </div>
</div>

<script>
    // 提交后关闭本窗口并刷新父页面
    document.getElementById('editForm').addEventListener('submit', function (e) {
        e.preventDefault();
        fetch(this.action, {
            method: 'POST',
            body: new FormData(this)
        }).then(res => res.text())
            .then(() => {
                if (window.opener) {
                    window.opener.location.reload();
                }
                window.close();
            });
    });
</script>

</body>
</html>